package com.twu.biblioteca.options;

import com.twu.biblioteca.Option;
import com.twu.biblioteca.UserRepository;

public class AuthenticationOptionDecorator implements Option {

    final Option decorated;
    private Option alternativeDecorated;
    private final UserRepository userRepository;


    public AuthenticationOptionDecorator(Option decorated, UserRepository userRepository) {
        this.decorated = decorated;
        this.userRepository = userRepository;
    }

    @Override
    public void Execute() {
        if (userRepository.isAuthenticated()) {
            this.decorated.Execute();
        }
        else if (alternativeDecorated != null) {
            this.alternativeDecorated.Execute();
        }
    }

    @Override
    public String toString() {
        return this.decorated.toString();
    }

    public void setAlternativeDecoratedOption(Option alternativeDecorated) {
        this.alternativeDecorated = alternativeDecorated;
    }
}
